package me.zhengjie.jdbcLinkDb;


import me.zhengjie.modules.stock.domain.Stock;
import me.zhengjie.modules.stock.domain.StockStore;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class JdbcToDbService {

    @Resource
    private JdbcTemplate jdbcTemplate;

    public void insertStock(){
      String sql="INSERT INTO `stock` (`id`, `stock_name`," +
              " `stock_code`, `stock_type`, `buy_price`, `sell_price`, " +
              "`buy_time`, `sell_time`, `hold_num`, `earn_money`, `share_mood`, " +
              "`pic_name`, `pic_path`, `create_by`, `update_by`, `create_time`, " +
              "`update_time`, `del_flag`) VALUES ('4461146662880808960', '测试jdbc', '603585'," +
              " '1', '17.94', '19.12', '2021-11-30 00:00:00', '2021-12-31 00:00:00', " +
              "'10', '231', NULL, '', '', 'test', 'admin', '2021-11-18 09:38:06', '2022-08-31 14:52:35', '0');";
      jdbcTemplate.execute(sql);
    }

    public List<Stock> getStock(){
        String sql="select * from stock";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<Stock>(Stock.class));
    }

    public List<StockStore> getStockStore(){
        String sql="select * from stock_store";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<StockStore>(StockStore.class));
    }

    public void delStock(){

        String sql="delete from stock where stock_name=?";
        jdbcTemplate.update(sql,"测试jdbc");

    }

}
